package com.lanxiao.cloud.modules.oauth.domain.listener;

import com.google.common.eventbus.Subscribe;
import com.lanxiao.cloud.modules.oauth.domain.event.PermissionChangEvent;
import com.lanxiao.cloud.modules.oauth.domain.event.PermissionChangEventPublisher;
import com.lanxiao.cloud.modules.oauth.domain.service.IPermissionService;
import org.springframework.stereotype.Component;

/**
 * 权限变更事件监听
 *
 * @author ：qiaoliang
 * @date ：2021-10-15
 */
@Component
public class PermissionChangEventListener {

  private final IPermissionService permissionService;

  public PermissionChangEventListener(
      PermissionChangEventPublisher permissionChangEventPublisher,
      IPermissionService permissionService) {
    this.permissionService = permissionService;
    permissionChangEventPublisher.register(this);
  }


  @Subscribe
  public void asyncPublishPermissionChange(PermissionChangEvent permissionChangEvent){
    // 初始化全局权限/用户权限
    permissionService.initCache();
  }

}
